package com.multicampus.simplewiki.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.multicampus.simplewiki.ctrl.RssFeedManager;
import com.multicampus.simplewiki.search.DocumentSearcher;
import com.sun.syndication.feed.synd.SyndFeed;

public class RssFeedController implements Controller {

	private final int START_PAGE = 1;
	private final int COUNT = 10;

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String queryString = request.getParameter("queryString");
		
		DocumentSearcher documentSeacher = new DocumentSearcher();
		RssFeedManager rssFeedManager = new RssFeedManager();
		SyndFeed feed = rssFeedManager.makeRSS(documentSeacher.search(queryString, START_PAGE, COUNT));
		
		ModelAndView mav =  new ModelAndView("/wikipage/view_rss");
		
		if (feed != null) {
			mav.addObject("feed", feed);
		}
		return mav;
	}
}
